import * as ActionTypes from './type'

export default {
  // 获取站点初始信息
  [ActionTypes.SITE_INIT]: (state, data) => {
    state.site = null
    state.alllanguage = null
    let site = {}
    site.site = data.site
    site.config = data.sConfig
    site.defaultdomain = data.defaultdomain
    site.list = data.siteList
    site.init = data.init
    for (let i in data.allLanguage) {
      let language = data.allLanguage[i]
      if (parseInt(language.id) === parseInt(site.site.languageId)) {
        site.language = language
        break
      }
    }

    state.site = site
    state.alllanguage = data.allLanguage

    state.host = null
    state.host = data.host

    state.loginDomain = data.loginDomain
    state.loginUrl = data.loginUrl
  },
  [ActionTypes.SITE_CHANGE]: (state, data) => {
    window.location.href = window.location.href
  },
  [ActionTypes.SITE_CHANGE_CONFIG_SITESEO]: (state, data) => {
    state.site.config.siteSeo = data.siteSeo
  },
  [ActionTypes.SITE_CONFIG_CHANGE]: (state, data) => {
    state.site.config = data
  }
}
